/*
  Meanwhile - Unofficial Lotus Sametime client library
  
  Copyright (c) 2007 Christopher O'Brien <siege@preoccupied.net>
  
  License: LGPL
  
  This library is free software; you can redistribute it and/or modify
  it under the terms of version 2 the GNU Library General Public
  License as published by the Free Software Foundation.
                                                                                
  This library is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA
*/


#include "mw-cipher.h"


GType mw_cipher_mode_get_type() {
  static GType type = 0;
  if(! type) {
    ;
  }
  return type;
}



MwEncrypt *mw_encrypt_new() {
  return g_new0(MwEncrypt, 1);
}


MwEncrypt *mw_encrypt_dup(const MwEncrypt *e) {
  MwEncrypt *n = mw_encrypt_new();
  mw_encrypt_copy(n, e);
  return n;
}


void mw_encrypt_copy(MwEncrypt *to, const MwEncrypt *from) {
  g_return_if_fail(to != NULL);
  g_return_if_fail(from != NULL);

  mw_encrypt_clear(to);
  to->mode = from->mode;
  mw_opaque_copy(&to->info, &from->info);
}


void mw_encrypt_read(MwReadBuffer *readb, MwEncrypt *e, GError **err) {
  MW_TRYLINE(err, MW_UNPACK(readb, err, "io", &e->mode, &e->info));
}


void mw_encrypt_write(MwWriteBuffer *writeb, const MwEncrypt *e) {
  MW_PACK(writeb, "io", e->mode, &e->info);
}


void mw_encrypt_clear(MwEncrypt *e) {
  g_return_if_fail(e != NULL);

  e->mode = 0;
  mw_opaque_clear(&e->info);
}


void mw_encrypt_free(MwEncrypt *e) {
  if(e) {
    mw_encrypt_clear(e);
    g_free(e);
  }
}


guint mw_encrypt_hash(const MwEncrypt *e) {
  return mw_opaque_hash(&e->opaque);
}


gboolean mw_encrypt_equal(const MwEncrypt *a, const MwEncrypt *b) {
  g_return_val_if_fail(a != NULL || b == NULL, FALSE);
  g_return_val_if_fail(b != NULL || a == NULL, FALSE);

  return ((a == b) ||
	  ((a->mode == b->mode) &&
	   mw_opaque_equal(&a->info, &b->info)));
}


/* The end. */
